const { MYSQL_CONF } = require('../conf/db')
const mysql = require('mysql')

const con = mysql.createConnection(MYSQL_CONF)
con.connect()//开始连接

function exec(sql){
    const promise = new Promise((reslove,reject)=>{
        con.query(sql,(err,res)=>{
            if(err){
                reject(err)
                return
            }
            reslove(res)
        })
    })
return promise
} 

// const sql = 'select * from users'
// const sql = `update users  set realname='李四2' where username='lisi'`


// con.end()//关闭
module.exports = { 
    exec,
    escape:mysql.escape
}